﻿using DAL.Register;
using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
   public class ReaderManagementDAL
    {
        /// <summary>
        /// 获取全部读者信息
        /// </summary>
        /// <returns></returns>
        public DataTable ReaderShowDAL()
        {
            string sql = $"SELECT ID ID ,ReaderID 读者编号,ReadName 读者姓名,EMail 读者邮箱,Address 读者住址,Mobile 读者手机号码 FROM ReaderInfo";
            return SQLHelper.Query(sql, null);
        }

        /// <summary>
        /// 查询读者信息
        /// </summary>
        /// <param name="readerId"></param>
        /// <returns></returns>
        public DataTable FindByReaderDAL(string readerId)
        {
            string sql = $"SELECT ID ID ,ReaderID 读者编号, ReadName 读者姓名,EMail 读者邮箱, Address 读者住址,Mobile 读者手机号码 FROM ReaderInfo WHERE ID = @ID; ";
            SqlParameter[] de = {
                new SqlParameter("@ID",readerId),
            };
            return SQLHelper.Query(sql, de);
        }

        /// <summary>
        /// 删除读者信息
        /// </summary>
        /// <param name="readerId">读者id</param>
        /// <returns></returns>
        public int DatateReaderDAL(string readerId)
        {
            string sql = $"DELETE FROM ReaderInfo WHERE ID=@ID";
            SqlParameter[] de = {
                new SqlParameter("@ID",readerId),
            };
            return SQLHelper.Close(sql, de);
        }

        /// <summary>
        /// 删除读者信息
        /// </summary>
        /// <returns></returns>
        public int UpdateReaderDAL(ReaderInfo reader)
        {
            string sql = $"UPDATE ReaderInfo SET ReaderID=@ReaderID,ReadName=@ReadName,EMail=@EMail ,Address=@Address ,Mobile=@Mobile WHERE ID = @ID";
            SqlParameter[] UPDATE = {
                new SqlParameter("@ID",reader.Id),
                new SqlParameter("@ReaderID",reader.ReaderId),
                new SqlParameter("@ReadName",reader.ReadName),
                new SqlParameter("@EMail",reader.Email),
                new SqlParameter("@Address",reader.Address),
                new SqlParameter("@Mobile",reader.Mobile),
            };
            return SQLHelper.Close(sql, UPDATE);
        }

      
    }
}
